package com.littlespider.utillibrary;

import android.content.Context;
import android.widget.Toast;

/**
 * Created by littlespider on 2018/10/10.
 */
public class ToastUtil {

    Context context;
    Toast toast;

    public ToastUtil(Context context){
        this.context = context;
    }

    /**
     * 一个弹出吐司的工具类, 防止吐司会一直弹出
     * @param messageStr 要弹出的提示内容
     */
    public void show(String messageStr){
        show(messageStr, false);
    }

    /**
     * 同上
     * @param messageStr
     * @param isLong 跟据传入的值决定吐司的持续时长, true为长, false为短
     */
    public void show(String messageStr, boolean isLong){
        if (toast != null){
            toast.cancel();
        }
        int timeParam = isLong?Toast.LENGTH_LONG:Toast.LENGTH_SHORT;
        toast = Toast.makeText(context, messageStr, timeParam);
        toast.show();
    }
}
